package com.paomi.client.activity.person.Adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.paomi.client.R;
import com.paomi.client.activity.person.model.IntegralDetailBean;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class IntegralRecordAdapter extends RecyclerView.Adapter<IntegralRecordAdapter.ViewHolder> {
    private Context context;
    private List<IntegralDetailBean> data = new ArrayList<>();

    public IntegralRecordAdapter(Context context) {
        this.context = context;

    }

    public void setData(List<IntegralDetailBean> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_intergral_record, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        if (position < data.size()) {
            IntegralDetailBean entity = data.get(position);
            if (entity.getOpt()==1) {
                holder.tv_point.setText("-" + entity.getValue());
                holder.tv_point.setTextColor(context.getResources().getColor(R.color.blue_2B7BEF));
            } else {
                holder.tv_point.setText("+" + entity.getValue());
                holder.tv_point.setTextColor(context.getResources().getColor(R.color.colorFF3B30));
            }
            holder.tv_msg.setText(entity.getRemark());
//            String time = new SimpleDateFormat("yyyy-MM-dd").format(entity.get);
            holder.tv_data.setText(entity.getYear()+"-"+entity.getMonth()+"-"+entity.getDay());
        }
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_msg)
        TextView tv_msg;
        @BindView(R.id.tv_data)
        TextView tv_data;
        @BindView(R.id.tv_point)
        TextView tv_point;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
